<!DOCTYPE html "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">


<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">快递名称：</label>
                            <div class="col-sm-10">
                                <input id="shipName" name="shipName" 
                                       class="form-control" type="text" maxlength="20">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">快递代码：</label>
                            <div class="col-sm-10">
                                <input id="shipCode" name="shipCode" 
                                       class="form-control" type="text" maxlength="20">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">快递类型:</label>
                            <div class="col-sm-10">
                                <select id="shipType" name="shipType" 
                                        data-placeholder="状态" class="form-control chosen-select" >
                                    <option value="1">快递</option>
                                    <option value="2">物流</option>
                                </select>
                            </div>
                        </div>

                        <div class="text-right form-group">
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    $().ready(function () {
        validateRule();
    });



    $.validator.setDefaults({
        submitHandler: function () {
            save();
        }
    });


    function save() {
        //var content_sn = $("#content_sn").summernote('code');
        //$("#productDetail").val(content_sn);
        $.ajax({
            cache: true,
            type: "POST",
            url: "/app/shipCfg/save",
            data: $('#signupForm').serialize(), // 你的formid
            async: false,
            success: function (data) {
                layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);
            }
        });
    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                shipName: {
                    required: true,
                    remote : {
                        url : "/app/shipCfg/shipCfgNameExit", // 后台处理程序
                        type : "post", // 数据发送方式
                        dataType : "json", // 接受数据格式
                        data : { // 要传递的数据
                            shipName : function() {
                                return $.trim($("#shipName").val());
                            }
                        }
                    }
                },
                shipCode:{
                    required: true,
                    remote : {
                        url : "/app/shipCfg/shipCfgNameExit", // 后台处理程序
                        type : "post", // 数据发送方式
                        dataType : "json", // 接受数据格式
                        data : { // 要传递的数据
                            shipCode : function() {
                                return $.trim($("#shipCode").val());
                            }
                        }
                    }

                },
                shipType:{
                    required: true
                }
            },
            messages: {
                shipName: {
                    required: icon + "必填",
                    remote : icon + "快递名称已存在"
                },
                shipCode: {
                    required: icon + "必填",
                    remote : icon + "快递代码已存在"
                },
                shipType: {
                    required: icon + "必填"
                }
            }
        })
    }

</script>
</body>
</html>